﻿using System;
using System.Web.Mvc;
using Beeldbankmvc.Models;

namespace Beeldbankmvc.Controllers
{
    [HandleErrorWithELMAH]
    public class RatingController : Controller
    {
        [HttpPost]
        public JsonResult Index(int rate, int mediaObjectId)
        {
            try
            {
                StarRatingRepository StarRatingRep = new StarRatingRepository();

                string ipAddress = "";
                if (Request != null)
                    ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

                StarRatingRep.Add(rate.ToString(), mediaObjectId, ipAddress);

                StarRatingModel ratingModel = StarRatingRep.FindOne(mediaObjectId);

                return Json(ratingModel);
            }
            catch
            {
                return Json(1);
            }
        }
    }
}
